<?php $CI =& get_instance()?>
<h2 class="dialog_title"><span>Rata - rata Pelanggaran</span></h2>
<div class="dialog_content" style="padding: 10px 20px; width:700px">
<?php $CI->load->model(array('departemen_model','jabatan_model','karyawan_history_jabatan_model','penilaian_model'))?>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
		<td>Bidang : </td>
		<td><strong><?php echo $achiev_bidang?></strong></td>
	</tr>
	<tr>
		<td width="80">Periode : </td>
		<td><strong>
			<?php if ($startPeriode == $endPeriode) : ?>
				<?php echo date("F-Y", strtotime($startPeriode)) ?>
			<?php else: ?>
				<?php echo date("F-Y", strtotime($startPeriode)) ?> - <?php echo date("F-Y", strtotime($endPeriode)) ?>
			<?php endif?>
			</strong></td>
	</tr>
</table>
<?php $z=0;?>
<table class="zebraable" width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr class="header">
  	<td align="left"><span class="colorWhite">No</span></td>
  	<td align="left"><span class="colorWhite">Tgl Pengesahan</span></td>
    <td align="left"><span class="colorWhite">Jenis</span></td>
    <td align="left"><span class="colorWhite">Bidang</span></td>
    <td align="left"><span class="colorWhite">Tingkat</span></td>
    <td align="left"><span class="colorWhite">Kategori</span></td>
    <td align="right"><span class="colorWhite">Perbuatan Ke</span></td>
    <td align="right"><span class="colorWhite">Point</span></td>  
  </tr>
  <tbody id="searchKary-table" style="overflow:scroll; height:200px; max-heigh:500px" >
<?php
	$CI->penilaian_model->join('prestasi_pelanggaran_detil','prestasi_pelanggaran_detil.detachiev_id=penilaian.detachiev_id');
	$CI->penilaian_model->join('prestasi_pelanggaran','prestasi_pelanggaran.achiev_id=prestasi_pelanggaran_detil.achiev_id');
	$CI->penilaian_model->join('karyawan','karyawan.kary_id=penilaian.kary_id');
	$CI->penilaian_model->join('karyawan_history_jabatan','karyawan_history_jabatan.kary_jbt_id=penilaian.kary_jbt_id');
	$CI->penilaian_model->join('jabatan','jabatan.jbt_id=karyawan_history_jabatan.jbt_id');
	$CI->penilaian_model->join('departemen','departemen.dep_id=jabatan.dep_id');
	$CI->penilaian_model->order_by('kary_nama asc, point_tgl_aktif asc');
	$penilaianData = $CI->penilaian_model->get_where("prestasi_pelanggaran.achiev_bidang='$achiev_bidang' ".
		"AND date_format(point_tgl_aktif,'%Y-%m') BETWEEN date_format('$startPeriode','%Y-%m') AND date_format('$endPeriode','%Y-%m')");
		
	$jmlPunishment = 0;
	$jmlPerbuatan = 0;
	$karyID = 0;
?>
<?php if ($penilaianData->num_rows()>0):?>
	<?php foreach ($penilaianData->result_array() as $row): ?>
	<?php $jmlPerbuatan++;?>
	
	<?php 
		//kita hitung jumlah record reward disini,
		if ($row['achiev_jenis']=='PE') {
			$jmlPunishment++;
		}
		//bukan reward, continue loop
		else {
			continue;
		}
	?>
	
	
	<?php if (!$karyID || $karyID != $row['kary_id']): ?>
	  <tr class="notification">
		<td colspan="8"><?php echo $row['kary_nama']?> (<?php echo $row['kary_nama']?>)</td>
		<?php $karyID = $row['kary_id']?>
	  </tr>
	<?php endif ?>

	  <tr  <?php if($z++%2==0):?>class="zebra"<?php endif?>>
		<td><?php echo $z?></td>
		<td><?php echo $row['point_tgl_aktif']?></td>
		<td><?php echo $jenis_options[$row['achiev_jenis']]?></td>
		<td><?php echo $row['achiev_bidang']?></td>
		<td><?php echo $tingkat_options[$row['detachiev_tingkat']]?></td>
		<td><?php echo $row['detachiev_nama']?></td>
		<td align="right"><?php echo $row['point_count']?></td>
		<td align="right"><?php echo $row['point_point']?></td>
	  </tr>
	<?php endforeach?>
<?php else : ?>
	<tr>
		<td colspan="8" align="center"><strong>tidak ada data</strong></td>
	</tr>
<?php endif;?>
  </tbody>
  <tr class="header">
    <th align="right" colspan="7"><span class="colorWhite">Jumlah Pelanggaran : </span></th>
    <th align="right"><span class="colorWhite"><?php echo number_format($jmlPunishment,2) ?></span></th>  
  </tr>
  <tr class="header">
    <th align="right" colspan="7"><span class="colorWhite">Jumlah Laporan : </span></th>
    <th align="right"><span class="colorWhite"><?php echo number_format($jmlPerbuatan,2) ?></span></th>  
  </tr>
  <tr class="header">
    <th align="right" colspan="7"><span class="colorWhite">Rata - rata Pelanggaran : </span></th>
    <th align="right"><span class="colorWhite"><?php echo number_format($jmlPerbuatan? $jmlPunishment/$jmlPerbuatan : 0,2) ?></span></th>  
  </tr>
</table>
</div>
<div class="dialog_buttons"><input type="button" value="Close" name="close" onclick="FBModal_hide()" /></div>